home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part2 / 11018 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  887 b 

  1. Path: ccshst05.cs.uoguelph.ca!ccshst01!thay
  2. From: thay@uoguelph.ca (Toby K Hay)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: Rand() Function
  5. Date: 21 Mar 1996 14:53:18 GMT
  6. Organization: University of Guelph
  7. Message-ID: <4irqgu$gml@ccshst05.cs.uoguelph.ca>
  8. References: <4iqltj$40g@news1.sympatico.ca>
  9. NNTP-Posting-Host: ccshst01.cs.uoguelph.ca
  10. X-Newsreader: TIN [version 1.2 PL2]
  11.  
  12. Gisele Swinson (gisele.swinson@sympatico.ca) wrote:
  13. : How do I get a random number from a "SET" of numbers.
  14. :       I want a random number from this set:
  15. :       2, 4, 6, 8, 10
  16. : It seems so simple but I can't find anything in my text how to do this.
  17.  
  18. The FAQ for this group has the following for numbers chosen at random in 
  19. the range 0 to N-1:  rand()/(RAND_MAX/N + 1)
  20. For the above sequence you would use 5 for N, multiply by 2, and add 2.
  21. result = 2 + (2 * rand()/(RAND_MAX/5 + 1))
  22. Toby Hay    thay@uoguelph.ca
  23.